﻿/*
***************************************************************************
* Microsoft Visual C# .NET
* 名称：       Shpm.System.Db.AceBaseDao
* 类型：       数据库访问对象抽象类
* 功能说明：   继承此类，实现对数据库的访问操作
* 作者：       SHPM.彭城东
* 创建日期：   2007/07/10
* 修改日期     修改者      修改内容* 
***************************************************************************
*/

using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Data.SqlClient;
using IBatisNet.DataMapper;
using IBatisNet.DataMapper.Configuration;
using System.Reflection;
using System.Collections.Specialized;
using log4net;

namespace Shpm.System.Db
{
    public abstract class AceBaseDao : ComBaseDao
    {
        private const string MAPPING_CONFIG = "SqlMap.ace.config";

        protected static ILog log = LogManager.GetLogger(typeof(AceBaseDao));

        protected static SqlMapper sqlMapClient = null;

        protected override ILog getLogger()
        {
            return log;
        }

        protected override SqlMapper getSqlMapClient()
        {
            if (sqlMapClient == null)
            {
                lock (typeof(SqlMapper))
                {
                    if (sqlMapClient == null)
                    {					    
					    try
                        {
                            DomSqlMapBuilder build = new DomSqlMapBuilder();
                            sqlMapClient = (SqlMapper)build.Configure(MAPPING_CONFIG);
					    }
					    catch(Exception e) {
						    sqlMapClient = null;
                            log.Fatal(e);
                            throw new DataAccessException("The configuration file is invalid." + e.Message, e);
					    }
				    }
			    }
		    }
		    return sqlMapClient;
	    }
    }
}